package com.cn.qtms.common.condition;

import com.cn.qtms.util.DateUtils;
import org.springframework.data.jpa.domain.Specification;

import java.util.Date;

/**
 * @author User
 */
public interface ICondition {
	/**
	 * 转成字符串，进行拼接
	 * @return
	 */
	String toStrCondition();

	/**
	 * 转criteria查询
	 * @param <T>
	 * @return
	 */
	<T> Specification<T> c2s();

	/**
	 * 复制一份
	 * @return
	 */
	ICondition copy();

	/**
	 * Object类型转换
	 * @param value
	 * @return
	 */
	public default String getValueStr(Object value) {
		if(value instanceof Number) {
			return "" + value + "";
		}
		if(value instanceof Date) {
			return "'" + DateUtils.format((Date) value) + "'";
		}
		
		return "'" + value + "'";
	}
}
